// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
    env: "yiliaojiufeng-6gt0kj1l1df8b7b7",
    traceUser: true,
})

const db = cloud.database()

// 云函数入口函数
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()

    var time = new Date().getTime()

    try {
        return await db.collection('comment').add({
            // data 字段表示需新增的 JSON 数据
            data: {
                artId: event.artId,
                openid: wxContext.OPENID,
                content: event.content,
                time: time
            }
        })
    } catch (e) {
        console.error(e)
    }
}